// 文章列表 生成
import { ref, reactive } from 'vue'
import { tagArticleList } from '@/api/home'



// 每页几条
const currentSize = 10

const articleList = ref([])
const paging = reactive({
    page: 1,
    size: currentSize,
})

export default function articleListFn(router) {

    // 根据标签id获取文章列表
    const getArticleListFn = async (tagId) => {
        console.log(tagId);
        
        let { status, result } = await tagArticleList(tagId, paging.page, paging.size)

        if (status != 200) return
        
        articleList.value = result
    }

    // 重置分页
    const resetPageingGetArticleListFn = (tagId) => {
        paging.page = 1
        paging.size = currentSize
        getArticleListFn(tagId)
    }

    // 转跳文章页面
    const toArticleFn = (id) => {
        console.log('router', router);
        router.push({
            name: 'article',
            params: { id },
        })
    }

    return {
        paging,
        articleList,
        resetPageingGetArticleListFn,
        toArticleFn,
    }
}